package top.heathylife.pagehelperx.comparator;

import top.heathylife.pagehelperx.other.TypeFunction;

import java.util.Comparator;

/**
 * 降序比较器
 *
 * @author maoxiaomeng
 *
 */
public  class DescComparator<T> implements Comparator<T> {

    private TypeFunction<T, ?> key;

    private void setKey(TypeFunction<T, ?> key) {
        this.key = key;
    }

    public static <T> DescComparator<T> getInstance(TypeFunction<T, ?> key) {
        DescComparator<T> objectDescComparator = new DescComparator<>();
        objectDescComparator.setKey(key);
        return objectDescComparator;
    }

    @Override
    public int compare(T o1, T o2) {
        return Integer.compare(0, AscComparator.getInstance(key).compare(o1, o2));
    }
}
